package com.hq.ims.data.vo;

import com.hq.authority.utils.AppUtils;
import com.hq.ims.data.config.verification.VdAdd;
import com.hq.ims.data.config.verification.VdEdit;
import com.hq.ims.data.entity.PermissionGroup;
import com.hq.ims.data.entityenum.EnumGroupType;
import com.hq.ims.data.vo.auth.BaseRowAuthVo;
import com.hq.utils.util.ListUtils;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.stream.Collectors;


/**
 * @author 蒋柏平
 * @since 20240929
 */
@Mapper
public interface PermissionGroupMapstruct {

    PermissionGroupMapstruct INSTANCE = Mappers.getMapper(PermissionGroupMapstruct.class);

    //-------------------------------- 转换VO类 --------------------------------

    @Mappings({
    })
    PermissionGroupVo toPermissionGroupVo(PermissionGroup source);


    default List<PermissionGroupVo> toPermissionAuthorityVoList(List<PermissionGroup> source) {
        if (source == null) {
            return ListUtils.newEmptyList();
        }
        return source.stream().map(this::toPermissionGroupVo).collect(Collectors.toList());
    }

    //-------------------------------- 以下为自定义类[输出对象] --------------------------------

    @ApiModel(value = "原始对象的扩展类")
    @Data
    class PermissionGroupVo extends PermissionGroup {

    }

    @ApiModel(value = "行级权限对象")
    @Data
    class PermissionGroupRowAuthVo extends BaseRowAuthVo {

        //自定义其它行级权限


        //构造函数
        public PermissionGroupRowAuthVo(PermissionGroup entity) {
            //当前操作用户ID
            String userId = AppUtils.getUserId();
        }

    }


    //-------------------------------- 以下为自定义类[输入对象] --------------------------------

    @ApiModel(value = "搜索VO")
    @Data
    class PageSearchVo {

        private String groupName;

        private EnumGroupType groupType;
    }

    @ApiModel(value = "搜索VO")
    @Data
    class SaveVo {

        @NotBlank(message = "组ID不能为空", groups = {VdEdit.class})
        private String permissionGroupId;

        @NotBlank(message = "组名不能为空", groups = {VdAdd.class, VdEdit.class})
        private String groupName;

        private Integer sortNumber = 0;

        @NotNull(message = "组类别不能为空", groups = {VdAdd.class, VdEdit.class})
        private EnumGroupType groupType;

        @NotBlank(message = "公司ID不能为空", groups = {VdAdd.class, VdEdit.class})
        private String companyId;

    }

    //-------------------------------- springboot验证标识 --------------------------------

}
